<%@page import="java.util.Map"%>
<%@page import="helpers.EscapeCharsHelper"%>
<%@page import="entities.ApplicationTemplate"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.TreeMap"%>
<%@page import="helpers.UrlHelper"%>

<%
TreeMap<String, String> check = (TreeMap<String, String>) request.getAttribute("check");
String success = (String) request.getAttribute("success");
ApplicationTemplate template = (ApplicationTemplate) request.getAttribute("template");
String form = (String) request.getAttribute("form");
%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="/admin/layouts/header.jsp" />

<script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="/admin/js/application_template_form.js"></script>

		<div class="maincontent noright">
        	<div class="maincontentinner">
                <ul class="maintabmenu multipletabmenu">
                	<li><a href="/admin/apptemplate/list">Template Manager</a></li>
                	<li class="current"><a><%=form.equalsIgnoreCase("edit") ? "Edit Site Template" : "Add New Site Template" %></a></li>
                </ul><!--maintabmenu-->
                
                <div class="content">
					<jsp:include page="/admin/elements/message_box.jsp" />
                    
                    <% if (check != null && check.size() > 0) { %>
					<div class="notification msgerror">
						<p>
						<%
						for(Map.Entry<String,String> entry : check.entrySet()) {
						%>
						<%=entry.getValue() %><br />
						<%
						}
						%>
						</p>
					</div>
					<% } %>
                    
                    <div class="one_fourth">
                    	<h3>Template Files</h3>
                    	
                        <br>
                        <div class="list-template">
                        	<p><label>Header Page</label> <a title="Edit" class="headerPageValue" id="header" href="#">(Edit)</a></p>
                        	<p><label>Footer Page</label> <a title="Edit" class="footerPageValue" id="footer" href="#">(Edit)</a></p>
	                    	<p><label>Homepage</label> <a title="Edit" class="homePageValue" id="homePage" href="#">(Edit)</a></p>
	                    	<p><label>Archives</label> <a title="Edit" class="archivesPageValue" id="archivesPage" href="#">(Edit)</a></p>
	                    	<p><label>Article Info</label> <a title="Edit" class="articleInfoPageValue" id="articleInfoPage" href="#">(Edit)</a></p>
	                    	<p><label>Author Article</label> <a title="Edit" class="authorArticlePageValue" id="authorArticlePage" href="#">(Edit)</a></p>
	                    	<p><label>Authors</label> <a title="Edit" class="authorsPageValue" id="authorsPage" href="#">(Edit)</a></p>
	                    	<p><label>Category</label> <a title="Edit" class="categoryPageValue" id="categoryPage" href="#">(Edit)</a></p>
	                    	<p><label>Tag</label> <a title="Edit" class="tagPageValue" id="tagPage" href="#">(Edit)</a></p>
	                    	<p><label>Contact</label> <a title="Edit" class="contactPageValue" id="contactPage" href="#">(Edit)</a></p>
	                    	<p><label>Rewriter</label> <a title="Edit" class="rewriterPageValue" id="rewriterPage" href="#">(Edit)</a></p>
	                    	<p><label>Static Page</label> <a title="Edit" class="staticPageValue" id="staticPage" href="#">(Edit)</a></p>
	                    	<p><label>Submit Article</label> <a title="Edit" class="submitArticlePageValue" id="submitArticlePage" href="#">(Edit)</a></p>
	                    	<p><label>Search</label> <a title="Edit" class="searchPageValue" id="searchPage" href="#">(Edit)</a></p>
	                    	<p><label>Library</label> <a title="Edit" class="libraryPageValue" id="libraryPage" href="#">(Edit)</a></p>
	                    </div>
	                    <br>
	                    <a href="/admin/apptemplate/restore/<%=template.getId() %>" class="restore-default">(Restore Template Default)</a>
                        
	                    <br /><hr /><br />
	                    <form method="post" class="stdform">
	                    	<p>
	                        	<span>Title</span> <br />
	                            <span>
	                            	<input type="text" class="longinput" name="title" id="a_title" value="<%=template.getTitle() %>">
	                            	<% if (check.get("title") != null) { %>
										<label for="g_title" generated="true" class="error"><%=check.get("title") %></label>
									<% } %>
	                            </span>
	                        </p>
	                        
	                        <p>
	                        	<span>Description</span> <br />
	                            <span>
	                            	<textarea type="text" class="longinput" name="description" id="a_description"><%=template.getDescription() %></textarea>
	                            	<% if (check.get("title") != null) { %>
										<label for="g_title" generated="true" class="error"><%=check.get("title") %></label>
									<% } %>
	                            </span>
	                        </p>
	                        
	                         <p>
	                        	<span>Base Url</span> <br />
	                            <span>
	                            	<%=template.getBaseUrl() %>
	                            </span>
	                        </p>
	                    
		                    <div class="hidden" style="display: no">
		                    	<textarea id="headerPageValue" name="header" style="display: none;"><%=template.getHeader() %></textarea>
								<textarea id="footerPageValue" name="footer" style="display: none;"><%=template.getFooter() %></textarea>
								<textarea id="homePageValue" name="home" style="display: none;"><%=template.getHome() %></textarea>
								<textarea id="archivesPageValue" name="archives" style="display: none;"><%=template.getArchives() %></textarea>
								<textarea id="articleInfoPageValue" name="articleInfo" style="display: none;"><%=template.getArticleInfo() %></textarea>
								<textarea id="authorArticlePageValue" name="authorArticle" style="display: none;"><%=template.getAuthorArticle() %></textarea>
								<textarea id="authorsPageValue" name="authors" style="display: none;"><%=template.getAuthors() %></textarea>
								<textarea id="categoryPageValue" name="category" style="display: none;"><%=template.getCategory() %></textarea>
								<textarea id="tagPageValue" name="tag" style="display: none;"><%=template.getTag() %></textarea>
								<textarea id="contactPageValue" name="contact" style="display: none;"><%=EscapeCharsHelper.forHTML(template.getContact()) %></textarea>
								<textarea id="rewriterPageValue" name="rewriter" style="display: none;"><%=EscapeCharsHelper.forHTML(template.getRewriter()) %></textarea> 
								<textarea id="staticPageValue" name="staticPage" style="display: none;"><%=template.getStaticPage() %></textarea> 
								<textarea id="submitArticlePageValue" name="submitArticle" style="display: none;"><%=EscapeCharsHelper.forHTML(template.getSubmitArticle())%></textarea>
								<textarea id="searchPageValue" name="search" style="display: none;"><%=EscapeCharsHelper.forHTML(template.getSearch())%></textarea>
								<textarea id="libraryPageValue" name="library" style="display: none;"><%=template.getLibrary()%></textarea>
							</div>
		                    <div class="save-change">
		                    	<button class="stdbtn btn_black">Save All Change</button>
		                    	<button class="stdbtn btn_black" type="reset">Reset</button>
		                    </div>
	                    </form>
                    </div>
                    
                    <div class="three_fourth preview-template last">
                    	<h3>Edit <span class="label-page-edit"></span></h3>
                    	<div class="template-panel">
                        	<button class="stdbtn btn_blue">Apply</button>
                        </div>
                        <br>
                    	<textarea name="pageValue" id="pageValue" rows="20" cols="118" class="hidden" ></textarea>
						<div>
							<div id="template-editor"></div>
						</div>
                    </div>
                    
                    <br clear="all">
                    
                </div><!--content-->
                
            </div><!--maincontentinner-->
            
            <jsp:include page="/admin/elements/copyright.jsp" />
            
        </div>

<jsp:include page="/admin/layouts/footer.jsp" />